package com.showcai.service.impl;

import com.showcai.module.Prizes;
import com.showcai.service.ServiceBase;

import java.util.List;
import java.util.Random;

/**
 * Created by Baggio on 2018-12-19.
 */
public class DrawGameBase extends ServiceBase {
    /**
     * 加权随机奖品
     * @param prizesList
     * @return
     */
    protected Prizes weightedRandomPrizes(List<Prizes> prizesList) {
        // 根据奖品集合返回中奖的奖品所在集合的索引
        Prizes prizes=new Prizes();
        int random = new Random().nextInt(10000);
        int prizeRate = 0;  // 中奖率
        for (int i = 0; i < prizesList.size(); i++) {
            prizes= prizesList.get(i);
            Integer probability = prizesList.get(i).getProbability();
            prizeRate += probability;
            if (random < prizeRate) {
                logger.warn("奖品为：" + prizes.getName() + "  概率："
                        + prizes.getProbability() + " 随机数random：" + random
                        + " 概率基数prizeRate：" + prizeRate);
                break;
            }
        }
        return prizes;

    }

    /**
     * 完全随机奖品
     * @param prizesList
     * @return
     */
    protected Prizes randomPrizes(List<Prizes> prizesList) {
        // 根据奖品集合返回中奖的奖品所在集合的索引
        int random = new Random().nextInt(prizesList.size()-1);
        Prizes prizes=prizesList.get(random);
        return prizes;
    }

    protected void addawardsLog(Prizes prizes,Long userId){

    }
}
